package com.sekill.goods.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.seckill.common.core.web.controller.BaseController;
import com.sekill.goods.entity.Seckill;
import com.sekill.goods.entity.Stock;
import com.sekill.goods.entity.TbSku;
import com.sekill.goods.service.ISeckillService;
import com.sekill.goods.service.IStockService;
import com.sekill.goods.service.ITbSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 库存表，代表库存，秒杀库存等信息 前端控制器
 * </p>
 *
 * @author huhu
 * @since 2021-06-22
 */
@RestController
@RequestMapping("/stock")
public class StockController extends BaseController {

    @Autowired
    private ITbSkuService iTbSkuService;

    @Autowired
    private ISeckillService iSeckillService;

    @Autowired
    private IStockService iStockService;

    @GetMapping("getGoodsList")
    public Object getGoodsList() {
        startPage();
        List<TbSku> list = iTbSkuService.list();
        return getDataTable(list);
    }

    @PostMapping("addMiao")
    public boolean addMiao(@RequestBody Seckill seckill) {
        seckill.setSeckillUpdate(new Date());
        seckill.setStatus(1);
        //3234246
        boolean save = iSeckillService.save(seckill);
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sku_id",seckill.getSkuId());
        Stock byId = iStockService.getOne(queryWrapper);
        byId.setSeckillStock(seckill.getSeckillStock());
        /*UpdateWrapper<Object> updateWrapper = new UpdateWrapper<>();
        updateWrapper*/
        boolean b = iStockService.updStock(byId);
        return b;
    }
}
